//
//  HomeTableDetailController.m
//  RentTable
//
//  Created by mac on 2024/11/29.
//

#import "HomeTableDetailController.h"
#import "TradView.h"
#import "OrderSelectPageView.h"
#import "HomeConfirmOrderController.h"

@interface HomeTableDetailController ()

@property (nonatomic, strong) UIScrollView *contentScollView;

@property (nonatomic, strong) UIImageView *backImageView;
@property (nonatomic, strong) UILabel *hotLabel;
@property (nonatomic, strong) UILabel *hotTitleLabel;
@property (nonatomic, strong) UIImageView *detailImageView;
@property (nonatomic, strong) UILabel *depPriceleLabel;

@end

@implementation HomeTableDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = myRGBHex(0xF5F5F5);
    [self loadUI];
    [self setDetailTab];
}

- (void)setDetailTab {
    self.backImageView.image = [UIImage imageNamed:self.rentModel.rentImage];
    self.hotLabel.text = [NSString stringWithFormat:@"¥%.1f",self.rentModel.rentPrice];
    self.hotTitleLabel.text = self.rentModel.rentTitle;
    self.detailImageView.image = [UIImage imageNamed:self.rentModel.rentDetailImage];
    self.depPriceleLabel.text = [NSString stringWithFormat:@"¥%@",self.rentModel.rentDeposit];
}

- (void)loadUI {
    
    
    CGFloat contentHeight = 1260 * scaleH;
    self.contentScollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, spDeviceWidth, spDeviceHeight)];
    self.contentScollView.contentSize = CGSizeMake(spDeviceWidth, contentHeight);
    self.contentScollView.showsHorizontalScrollIndicator = NO;
    self.contentScollView.showsVerticalScrollIndicator = NO;
    self.contentScollView.contentInset = UIEdgeInsetsZero;
    self.contentScollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    [self.view addSubview:self.contentScollView];
    
    [self loadBackArrow];
    [self loadTitle:@"商品详情"];
    
    UIImageView *backImageView = [UIImageView new];
    backImageView.image = [UIImage imageNamed:@"1"];
    backImageView.contentMode = UIViewContentModeScaleAspectFill;
    [self.contentScollView addSubview:backImageView];
    [backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(40);
        make.centerX.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(294 * scaleW, 294 * scaleH));
    }];
    self.backImageView = backImageView;
    
    UIImageView *hotGoodImageview = [UIImageView new];
    hotGoodImageview.image = [UIImage imageNamed:@"价格卡片"];
    [self.contentScollView addSubview:hotGoodImageview];
    [hotGoodImageview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(305 * scaleH);
        make.width.mas_equalTo(spDeviceWidth);
        make.height.mas_equalTo(70 * scaleH);
    }];
    
    UILabel *hotLabel = [UILabel new];
    hotLabel.text = @"¥59.9";
    hotLabel.font = [UIFont pingFangSCRegularWithSize:28];
    hotLabel.textColor = myRGBHex(0xFFFFFF);
    hotLabel.textAlignment = NSTextAlignmentLeft;
    [hotGoodImageview addSubview:hotLabel];
    [hotLabel sizeToFit];
    [hotLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(14 * scaleH);
        make.leading.mas_equalTo(16);
        make.height.mas_equalTo(25);
    }];
    self.hotLabel = hotLabel;
    
    UILabel *hotDayLabel = [UILabel new];
    hotDayLabel.text = @"/天";
    hotDayLabel.font = [UIFont pingFangSCSemiboldWithSize:12];
    hotDayLabel.textColor = myRGBHex(0xFFFFFF);
    hotDayLabel.textAlignment = NSTextAlignmentLeft;
    [hotGoodImageview addSubview:hotDayLabel];
    [hotDayLabel sizeToFit];
    [hotDayLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(hotLabel.mas_bottom).offset(0);
        make.leading.equalTo(hotLabel.mas_trailing).offset(10);
        make.height.mas_equalTo(15);
    }];
    
    UILabel *hotDetailLabel = [UILabel new];
    hotDetailLabel.text = @"1个月起租";
    hotDetailLabel.font = [UIFont pingFangSCMediumWithSize:10];
    hotDetailLabel.textColor = myRGBHex(0xFFFFFF);
    hotDetailLabel.textAlignment = NSTextAlignmentLeft;
    [hotGoodImageview addSubview:hotDetailLabel];
    [hotDetailLabel sizeToFit];
    [hotDetailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(hotLabel.mas_bottom).offset(7);
        make.leading.mas_equalTo(19);
        make.height.mas_equalTo(15);
    }];
    
    UIView *midView = [UIView new];
    midView.backgroundColor = myRGBHex(0xFFFFFF);
    [self.contentScollView addSubview:midView];
    [midView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(hotGoodImageview.mas_bottom);
        make.width.mas_equalTo(spDeviceWidth);
        make.height.mas_equalTo(309 * scaleH);
    }];
    
    UILabel *hotTitleLabel = [[UILabel alloc] init];
    hotTitleLabel.font = [UIFont pingFangSCSemiboldWithSize:17];
    hotTitleLabel.textColor = myRGBHex(0x333333);
    hotTitleLabel.textAlignment = NSTextAlignmentLeft;
    hotTitleLabel.numberOfLines = 0;
    [midView addSubview:hotTitleLabel];
    [hotTitleLabel sizeToFit];
    [hotTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(20);
        make.leading.mas_equalTo(16);
        make.trailing.mas_equalTo(-16);
        make.height.lessThanOrEqualTo(@50);
    }];
    hotTitleLabel.text = @"台球桌标准型钢库中式黑八台球厅会所家用成人台球桌自动回球";
    self.hotTitleLabel = hotTitleLabel;
    
    UILabel *tableLabel = [UILabel new];
    tableLabel.text = @"中八台球";
    tableLabel.font = [UIFont pingFangSCRegularWithSize:13];
    tableLabel.textColor = myRGBHex(0x999999);
    tableLabel.textAlignment = NSTextAlignmentCenter;
    [midView addSubview:tableLabel];
    [tableLabel sizeToFit];
    [tableLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(hotTitleLabel.mas_bottom).offset(18);
        make.leading.mas_equalTo(16);
        make.size.mas_equalTo(CGSizeMake(70, 27));
    }];
    tableLabel.backgroundColor = myRGBHexAlpha(0xCCCCCC, 0.2);
    tableLabel.layer.cornerRadius = 5;
    tableLabel.layer.masksToBounds = true;
    
    UIView *depositView = [UIView new];
    depositView.frame = CGRectMake(16, 129, spDeviceWidth - 32, 44);
    [midView addSubview:depositView];
    
    [CommondHandle gradientTheView:depositView bounds:depositView.bounds colors:@[myRGBHex(0x14ADFF),myRGBHex(0x12FFEB)] startPoint:CGPointMake(0, 0.5) endPoint:CGPointMake(1, 0.5) hasCornerRadius:10 shouldTakeBack:false];
    
    UILabel *depleLabel = [UILabel new];
    depleLabel.text = @"商品押金";
    depleLabel.font = [UIFont pingFangSCRegularWithSize:15];
    depleLabel.textColor = myRGBHex(0xFFFFFF);
    depleLabel.textAlignment = NSTextAlignmentLeft;
    [depositView addSubview:depleLabel];
    [depleLabel sizeToFit];
    [depleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.leading.mas_equalTo(14);
        make.height.mas_equalTo(18);
    }];
    
    UIView *midDevidView = [UIView new];
    midDevidView.backgroundColor = myRGBHex(0xFFFFFF);
    [depositView addSubview:midDevidView];
    [midDevidView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.leading.equalTo(depleLabel.mas_trailing).offset(4);
        make.width.mas_equalTo(1);
        make.height.mas_equalTo(15);
    }];
    
    UILabel *depPriceleLabel = [UILabel new];
    depPriceleLabel.text = @"¥2000";
    depPriceleLabel.font = [UIFont pingFangSCRegularWithSize:15];
    depPriceleLabel.textColor = myRGBHex(0xFFFFFF);
    depPriceleLabel.textAlignment = NSTextAlignmentLeft;
    [depositView addSubview:depPriceleLabel];
    [depPriceleLabel sizeToFit];
    [depPriceleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.leading.equalTo(midDevidView.mas_trailing).offset(16);
        make.height.mas_equalTo(18);
    }];
    self.depPriceleLabel = depPriceleLabel;
    
    UIView *devidView = [UIView new];
    devidView.backgroundColor = myRGBHexAlpha(0xCCCCCC, 0.1);
    [midView addSubview:devidView];
    [devidView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(depositView.mas_bottom).offset(19);
        make.leading.trailing.mas_equalTo(0);
        make.height.mas_equalTo(5);
    }];
    
    UIImageView *babyDetailImageView = [UIImageView new];
    babyDetailImageView.image = [UIImage imageNamed:@"宝贝详情"];
    [midView addSubview:babyDetailImageView];
    [babyDetailImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.top.equalTo(devidView.mas_bottom).offset(18);
        make.size.mas_equalTo(CGSizeMake(150, 34));
    }];
    
    UIImageView *detailImageView = [UIImageView new];
    detailImageView.image = [UIImage imageNamed:@"zhongba1"];
    [self.contentScollView addSubview:detailImageView];
    [detailImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(midView.mas_bottom);
        make.width.mas_equalTo(spDeviceWidth);
        make.height.mas_equalTo(414 * scaleH);
    }];
    self.detailImageView = detailImageView;
    
    
    TradView *tradView = [TradView new];
    tradView.rentModel = self.rentModel;
    tradView.backgroundColor = myRGBHex(0xFFFFFF);
    [self.view addSubview:tradView];
    [tradView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.bottom.mas_equalTo(0);
        make.height.mas_equalTo(90);
    }];
    
    QLWEAKSELF
    tradView.tenantBlock = ^{
        [UIView animateWithDuration:0.5 animations:^{
            
            OrderSelectPageView *orderView = [[OrderSelectPageView alloc] initWithFrame:self.view.bounds];
            orderView.rentModel = self.rentModel;
            [weakSelf.view addSubview:orderView];
            orderView.orderSelect = ^{
                HomeConfirmOrderController *vc = [HomeConfirmOrderController new];
                vc.rentModel = self.rentModel;
                vc.hidesBottomBarWhenPushed = true;
                [weakSelf.navigationController pushViewController:vc animated:true];
            };
        }];
    };
        
    
}




@end
